#!/bin/bash
# 获取当期git分支的tag，如果有v-前缀，则取v-后面的数字作为版本号，没有符合的tag，结束脚本
tag=$(git describe --tags --abbrev=0)
if [[ $tag == v* ]]; then
  ver=${tag:1}
else
  echo "no v- prefix tag found"
  exit 1
fi

# 切换到项目根目录
cd ../../

mvn clean package
if [ $? -ne 0 ]; then
  echo "mvn build failed"
  exit 1
fi

cd judge-server/docker

cp ../target/*.jar ./

dos2unix *.sh

image=registry.cn-hangzhou.aliyuncs.com/bookshare-ruiya/oj-judge-server

# get latest version num
ver=210

tag=v-$ver

# build and push
docker build -t $image:latest -t $image:$tag .
docker push $image:latest
docker push $image:$tag

rm -rf *.jar

echo 'pushed image to '$image':v-'$ver